// ShmWriter.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "ArrayShm.h"

ArrayShm gArrayShm;

int main(int argc, char* argv[])
{
    bool bInitStat  =  false;
    do
    {    
        cout << "Going to open Shm for writing"<<endl;

        bInitStat = gArrayShm.init(szFileName,eWriter);
        if (false == bInitStat)
        {
            break;
        }
        const int nRuncnt = 10;
        for( int i = 0;i<nRuncnt;i++)
        {
            int index  =  rand()%100000;
			Data dt,dt1;
			memset(&dt,0,sizeof(Data));
            memset(&dt1,0,sizeof(Data));
#if defined _WIN32 || defined _WIN64
            SYSTEMTIME st;
            GetLocalTime(&st);
            sprintf_s(dt.acData,"value %d time is: %02d:%02d:%02d:%02d\n",index,st.wHour, st.wMinute,st.wSecond,st.wMilliseconds);
#elif defined   __linux__
			time_t rawtime;
			struct tm *tm;
			time( &rawtime );
			tm = localtime( &rawtime );
			sprintf(dt.acData,"value %d time is:%02d:%02d:%02d:%02d\n",i,tm->tm_hour, tm->tm_min,tm->tm_sec,0);
#endif
			bool bStat = gArrayShm.PutValue(dt, index);
			if (false ==bStat)
			{
		    }
            bStat = gArrayShm.PutValue(dt, 100000);
			if (false ==bStat)
			{
		    }
            bStat = gArrayShm.GetValue(dt1, index);
			if (false ==bStat)
			{
		    }
             
            printf("%s\n",dt.acData);
        }
    } while(0);
    //Sleep(10000);
    return 0;
}
